/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package arbeitsprotokoll.helper;

import java.util.GregorianCalendar;

/**
 *
 * @author FlorianB
 */
public class DateConverter {

    public static TimeObject getDifference(final GregorianCalendar start, final GregorianCalendar end) {
        TimeObject difference = new TimeObject();
        long timePassed = end.getTimeInMillis() - start.getTimeInMillis();

        int days = (int) (timePassed / (1000 * 60 * 60 * 24));
        timePassed = timePassed - ((long) days * 1000 * 60 * 60 * 24);

        int hours = (int) (timePassed / (1000 * 60 * 60));
        timePassed = timePassed - ((long) hours * 1000 * 60 * 60);

        int minutes = (int) (timePassed / (1000 * 60));
        timePassed = timePassed - ((long) minutes * 1000 * 60);

        difference.setYear(end.get(GregorianCalendar.YEAR) - start.get(GregorianCalendar.YEAR));
        difference.setDay(days);
        difference.setHour(hours);
        difference.setMinute(minutes);

        return difference;
    }
}
